import java.io.*;
import java.util.HashMap;

public class UserServiceImpl implements UserService{
    @Override
    public boolean login(String username, String password) {
        if(username.equals(password)){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean register(User user){
        try{
            String name = user.getName();
            File f = new File("E:/" + name + ".txt");
            f.createNewFile();
            FileWriter fw = new FileWriter(f);
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write("username : " + user.getUsername());
            bw.newLine();
            bw.write("password : " + user.getPassword());
            bw.newLine();
            bw.write("name : " + user.getName());
            bw.close();
            fw.close();
            File fr = new File("E:/" + "zhangsan" + ".txt");
            FileWriter fw2 = new FileWriter(fr);
            BufferedWriter bw2 = new BufferedWriter(fw2);
            bw2.write("username : " + user.getUsername());
            bw2.newLine();
            bw2.write("password : " + user.getPassword());
            bw2.newLine();
            bw2.write("name : " + user.getName());
            bw2.newLine();
            bw2.close();
            fw2.close();
            return true;
        }catch(Exception e){
            e.printStackTrace();
        }


        return true;
    }
}
